
import java.io.*;
import java.util.Arrays;

public class 数列区间最大值 {
    static int N = 100010;
    static int[] arr = new int[N];
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] str = in.readLine().split( " ");
        int n = Integer.parseInt(str[0]);int m = Integer.parseInt(str[1]);
        String[] str2 = in.readLine().split(" ");
        for (int i=1;i<=n;i++) arr[i] = Integer.parseInt(str2[i-1]);

        while(m-- >0) {
            String[] str3 = in.readLine().split(" ");
            int l = Integer.parseInt(str3[0]);int r = Integer.parseInt(str3[1]);
            int[] cpy =  Arrays.copyOfRange(arr,l,r+1);
            Arrays.sort(cpy);

            System.out.println(cpy[r-l]);
        }

    }
}
